package it.polimi.traveldream.ejb.bean;



import it.polimi.authentication.ejb.usermanagement.AddNewCity;
import it.polimi.authentication.ejb.usermanagement.Pacchetto;
import it.polimi.authentication.ejb.usermanagement.Citta;
import it.polimi.authentication.ejb.usermanagement.PacchettoCitta;
import it.polimi.authentication.ejb.usermanagement.PacchettoPredefinito;
import it.polimi.authentication.ejb.usermanagement.User;
import it.polimi.authentication.ejb.usermanagement.dto.CittaDTO;
import it.polimi.authentication.ejb.usermanagement.dto.PacchettoPredefinitoDTO;
import it.polimi.authentication.ejb.usermanagement.dto.Pacchetto_cittaDTO;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJBContext;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * Session Bean implementation class UserBean
 */
@Stateless
public class AggiungiNuovaCitta implements AddNewCity{


	@PersistenceContext
    private EntityManager em;
	
	public AggiungiNuovaCitta(){	
	}
	
	@Override
	public boolean add(CittaDTO city)
	{
		ArrayList <Citta> cittaApp = (ArrayList <Citta>) em.createNamedQuery("Citta.thisCitta").setParameter("city", city.getCitta()).getResultList();
		
		if (cittaApp.size()==0)
		{
			//crea nuovo pacchetto
			Citta newC = new Citta (city);
			//inserisci 	
			em.persist(newC);
			return true;
		}
		else
		{
			return false;
		}
		
	}

	
	
	
}
	
	



